package com.bwie.controller;

import com.bwie.pojo.TbMenu;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginVo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 小薛超人
 * @version 1.0
 * @description: TODO
 * @date 2025/7/18 14:07
 */
@RestController
@RequestMapping("/user/index")
@Api(tags = "用户操作")
public class IndexController {

    @Autowired
    TbUserService tbUserService;

    @PostMapping("/sendCode/{mobile}")
    @ApiOperation(value = "发送验证码")
    public R sendCode(@PathVariable("mobile") String mobile){
        if(mobile.length() != 11){
            return R.ERROR(500,"手机号码格式不正确");
        }
        return tbUserService.sendCode(mobile);
    }

    @PostMapping("/enrollUser")
    @ApiOperation(value = "注册用户")
    public R enrollUser(@RequestBody @Validated LoginVo loginVo){
        return tbUserService.enrollUser(loginVo);
    }

    @PostMapping("/userLogin")
    @ApiOperation(value = "用户登录")
    public R userLogin(@RequestBody @Validated LoginVo loginVo){
        return tbUserService.userLogin(loginVo);
    }

    @PostMapping("/getMenuTree")
    @ApiOperation(value = "获取菜单权限")
    public R getMenuTree(){
        return tbUserService.getMenuTree();
    }
}
